package com.guomao.filedemos;


import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.stream.Stream;

public class FileDemoM {


    public static void main(String[] args) throws IOException {

        Path dir = Paths.get("example_dir");
        Path file = dir.resolve("example.txt");

        // 创建目录
        if (!Files.exists(dir)) {
            Files.createDirectory(dir);
        }

        Files.write(file, "Hello World".getBytes());

        //方法引用
        Files.lines(file).forEach(System.out::println);

        BasicFileAttributes attr = Files.readAttributes(file, BasicFileAttributes.class);


        System.out.println(attr.size());

        //流式编程
        Stream<Path> stream = Files.walk(dir);

        stream.forEach(System.out::println);
    }
}
